<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新品有戏后台管理</title>
    <link href="__CSS__/boot.css" rel="stylesheet">
    <link href="__STATIC__/layui/css/layui.css" rel="stylesheet">
    <script src="__JS__/jquery.js"></script>
    <script src="__JS__/layer/layer.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <style>
        th{
            text-align: center;
            vertical-align: middle!important;
        }
    </style>
</head>
<body>
{include file="base/header" /}
<div style="height: 1px;"></div>
<button class="layui-btn layui-btn-danger" onclick="excel()">导出EXCEL</button>
<div style="float: right; margin-top: 5px;margin-bottom: 5px" class="box-title ">
    <form class="form-inline" action="{:url('index/shelves/index')}" method="get">
        <input type="text" name="title" value="<?php if(isset($title)) echo $title ?>" class="form-control" id="exampleInputEmail3" >
        <input type="submit" class="btn btn-default" value="搜索"/>
        <input type="button" onclick="res()" value="全部显示" class="btn btn-default"/>
    </form>
</div>

<table class="table table-bordered" style="width: 1300px;margin: 0 auto">
    <tr>
        <th>编号</th>
        <th>商家id</th>
        <th>产品名称</th>
        <!--<th>二维码</th>-->
        <!--<th>视频</th>-->
        <!--<th>产品介绍</th>-->
        <th>分类</th>
        <th>进货价</th>
        <!--<th>条形码</th>-->
        <th>合作模式</th>
        <th>状态</th>
        <th>邮寄地址</th>
        <th>操作</th>
    </tr>
    {foreach $res as $val}
    <tr id="del{$val.id}" style="text-align: center">
        <td>{$val.id}</td>
        <td>{$val.bid}</td>
        <td style="width: 200px">{$val.pname}</td>
        <!--<td><img src="__ROOT__\{$val.code}" width="50" height="50"></td>-->
        <!--<td><a href="{:url('index/shelves/preview')}?id={$val.id}">{$val.video|substr=###,0,10}</a></td>-->
        <!--<td>{$val.introduce|substr=###,0,10}</td>-->
        <td>{$val.category}</td>
        <td>{$val.purchaseprice}元</td>
        <!--<td>{$val.retailprice}元</td>-->
        <td>{if $val.cooperation == 1} 进货价采购 {else/} 少量货物月结 {/if}</td>
        <td>{if $val.status == 7} 已上架 {/if}</td>
        <td style="width: 200px">{$val.customer}</td>
        <td>
            <!--<button onclick="del({$val.id})" type="button" class="btn btn-danger btn-xs">删除</button>-->
            <button onclick="picture({$val.id})" type="button" class="btn btn-primary btn-xs" >查看图片</button>
            <button onclick="edit({$val.id},{$val.bid})" type="button" class="btn btn-info btn-xs" >编辑</button>
            <button type="button" onclick="belt({$val.id})" class="btn btn-warning btn-xs">代发</button>
            <button type="button" onclick="copy({$val.id})" class="btn btn-success btn-xs">复制</button>
            <button type="button" onclick="barcode({$val.id})" class="btn btn-default btn-xs">打印条形码</button>
            <button type="button" onclick="barcode2({$val.id})" class="btn btn-default btn-xs">打印条形码2</button>
        </td>
    </tr>
    {/foreach}
</table>
<div style="margin-left: 30px">{$res->render()}</div>

</body>
<script>
    //查看图片
    function picture(id) {
        window.location.href = "{:url('index/examine/image')}?id="+id;
    }
    //删除
    function del(id) {
        layer.confirm('你确定要删除吗',{bnt:['确定','取消']},
            function () {
                $.ajax({
                    url:"{:url('index/product/delete')}",
                    type:"post",
                    data:"id="+id,
                    datatype:"json",
                    success:function (data) {
                        if(data.success){
                            layer.alert(data.success);
                            $("#del"+id).remove();
                        }else{
                            layer.alert(data.error);
                        }
                    }
                });
            }
        );
    }
    //显示所有
    function res() {
        window.location.href = "{:url('index/shelves/index')}";
    }
    //修改
    function edit(id,bid) {
        window.location.href = "{:url('index/shelves/edit')}?id="+id+"&bid="+bid;
    }
    //代发
    function belt(id) {
        $.ajax({
            url:"{:url('index/shelves/belt')}",
            data:"id="+id,
            type:"post",
            dataType:"json",
            success:function (res) {
                if(res.success){
                    layer.msg(res.success,{icon:1,time:1000});
                    $("#del"+id).remove();
                }else if(res.error){
                    layer.alert(res.error);
                }
            }
        });
    }
    //复制
    function copy(id) {
        $.ajax({
            url:"{:url('index/shelves/copy')}",
            data:"id="+id,
            type:"post",
            dataType:"json",
            success:function (res) {
                if(res.success){
                    layer.msg(res.success,{icon:1,time:1000},function () {
                        window.location.reload();
                    })
                }else{
                    layer.msg(res.error,{icon:5,time:1000},function () {
                        window.location.reload();
                    })
                }
            }
        });
    }
    //打印条形码
    function barcode(id) {
        $.ajax({
            url:"{:url('index/shelves/print_barcode')}",
            data:"id="+id,
            type:"post",
            dataType:"json",
            success:function (res) {
                if(res.success){
                    layer.msg(res.success,{icon:1,time:2000});
                }else if(res.error){
                    layer.msg(res.error,{icon:5,time:2000});
                }
            }
        });
    }
    //打印条形码
    function barcode2(id) {
        $.ajax({
            url:"{:url('index/shelves/print_barcode2')}",
            data:"id="+id,
            type:"post",
            dataType:"json",
            success:function (res) {
                if(res.success){
                    layer.msg(res.success,{icon:1,time:2000});
                }else if(res.error){
                    layer.msg(res.error,{icon:5,time:2000});
                }
            }
        });
    }
    //生成excel
    function excel() {
        window.location.href = "{:url('index/excel/productExcel')}"
    }
</script>
</html>